package com.yansl.http.model;

import java.util.Date;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import lombok.Data;

/**
 * @description: Token存活值
 * @author: yansl.cn
 * @create: 2023-01-11 14:21
 */
@Data
public class TokenActive {

    /**
     * 延迟 60秒
     */
    private static final Integer DELAY_TIME = 5;
    /**
     * token名称
     */
    private String name;
    /**
     * token 值
     */
    private String token;

    /**
     * token 失效时间
     */
    private Integer expire;

    /**
     * 创建日期：获取Token日期
     */
    private Date createTime;

    public TokenActive() {
        this.expire = expire - DELAY_TIME;
        createTime = new Date();
    }

    /**
     * 计算超时时间
     *
     * @return
     */
    public boolean isTimeOut() {
        long between = DateUtil.between(createTime, new Date(), DateUnit.SECOND);
        return between < expire;
    }
}
